package com.bj58.heatmap.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class IOUtils {

	/**
	 * 读文件
	 * 
	 * @param file
	 * @return
	 */
	public static String readFile(File file) {
		String line_separator = "\n";
		StringBuilder html = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line = null;
			while ((line = br.readLine()) != null) {
				html.append(line);
				html.append(line_separator);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
			return html.toString();
		}
		return html.toString();
	}

	/**
	 * 写文件
	 * 
	 * @param content
	 * @param file
	 */
	public static void saveFile(String content, File file) {
		try {
			BufferedWriter bw = new BufferedWriter(new FileWriter(file));
			bw.write(content);
			bw.flush();
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
	}

	
}
